using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using NetduinoHappyHour.Hardware;
using NetduinoHappyHour.Util;
using SecretLabs.NETMF.Hardware.Netduino;

namespace NetduinoHappyHour.Hardware
{
    public class StepperSleep : IExecutable
    {
        private static OutputPort _sleepPort = null;

        public static bool IsSleepMode { get; set; }

        /// <summary>
        /// contructor with strin parameter to be called remote
        /// </summary>
        /// <param name="Sleep"></param>
        public StepperSleep(string Sleep)
            : this(BooleanHelper.Parse(Sleep))
        {
        }

        /// <summary>
        /// Initializes the base sleep parameter
        /// </summary>
        /// <param name="Sleep"></param>
        public StepperSleep(bool Sleep)
        {
            IsSleepMode = Sleep;
        }

        /// <summary>
        /// Execute writes the sleep status to the hardware, unless Execute() is called,
        /// IsSleeMode reflects only the objects state, not the robots state!
        /// </summary>
        public void Execute()
        {
            bool lowActiveSleep = !IsSleepMode;
            //DisplayMessage startupMessage = new DisplayMessage("StepperSleep", "IsSleepMode: " + IsSleepMode);
            //startupMessage.Execute();
            if (StepperSleep._sleepPort == null)
            {
                SystemConfig.Instance().RegisterPin(Pins.GPIO_PIN_D9, "StepperSleep");
                StepperSleep._sleepPort = new OutputPort(Pins.GPIO_PIN_D9, lowActiveSleep);
            }
            StepperSleep._sleepPort.Write(lowActiveSleep);
        }
    }
}
